package com.cq.hd.app.controller;

import com.cq.hd.app.biz.StatisticsBiz;
import com.cq.hd.app.dto.*;
import com.cq.hd.app.vo.*;
import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.entity.BusinessInfo;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/statistics")
@Api(tags = "统计相关接口")
public class StatisticsController extends BaseController {

    @Autowired
    private StatisticsBiz statisticsBiz;

    @ApiOperation(value = "全部数据概况数据统计")
    @ApiResponse(response = AllDataStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllData")
    public Result<AllDataStatisticsVo> getAllData(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                  AllDataStatisticsDto allDataStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllData(allDataStatisticsDto));
    }

    @ApiOperation(value = "全部数据概况数据趋势统计")
    @ApiResponse(response = AllDataTrendStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllDataTrend")
    public Result<List<AllDataTrendStatisticsVo>> getAllDataTrend(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                                  AllDataTrendStatisticsDto allDataTrendStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataTrendStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataTrendStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllDataTrend(allDataTrendStatisticsDto));
    }

    @ApiOperation(value = "全部数据交易数据统计")
    @ApiResponse(response = AllDataTradeStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllDataTrade")
    public Result<AllDataTradeStatisticsVo> getAllDataTrade(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                            AllDataStatisticsDto allDataStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllDataTrade(allDataStatisticsDto));
    }

    @ApiOperation(value = "全部数据交易数据趋势统计")
    @ApiResponse(response = AllDataTrendStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllDataTradeTrend")
    public Result<List<AllDataTrendStatisticsVo>> getAllDataTradeTrend(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                                       AllDataTradeTrendStatisticsDto allDataTradeTrendStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataTradeTrendStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataTradeTrendStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllDataTradeTrend(allDataTradeTrendStatisticsDto));
    }

    @ApiOperation(value = "全部数据用户数据统计")
    @ApiResponse(response = AllDataUserStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllDataUser")
    public Result<AllDataUserStatisticsVo> getAllDataUser(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                          AllDataStatisticsDto allDataStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllDataUser(allDataStatisticsDto));
    }

    @ApiOperation(value = "全部数据用户数据趋势统计")
    @ApiResponse(response = AllDataTrendStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAllDataUserTrend")
    public Result<List<AllDataTrendStatisticsVo>> getAllDataUserTrend(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                                      AllDataUserTrendStatisticsDto allDataUserTrendStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            allDataUserTrendStatisticsDto.setBusinessId(businessInfo.getId());
        }

        allDataUserTrendStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAllDataUserTrend(allDataUserTrendStatisticsDto));
    }

    @ApiOperation(value = "自卖数据核心数据统计")
    @ApiResponse(response = SellDataStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getSellData")
    public Result<SellDataStatisticsVo> getSellData(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                        SellDataStatisticsDto sellDataStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            sellDataStatisticsDto.setBusinessId(businessInfo.getId());
        }

        sellDataStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getSellData(sellDataStatisticsDto));
    }

    @ApiOperation(value = "自卖数据核心数据趋势统计")
    @ApiResponse(response = SellDataTrendStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getSellDataTrend")
    public Result<List<SellDataTrendStatisticsVo>> getSellDataTrend(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                                        SellDataTrendStatisticsDto sellDataTrendStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            sellDataTrendStatisticsDto.setBusinessId(businessInfo.getId());
        }

        sellDataTrendStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getSellDataTrend(sellDataTrendStatisticsDto));
    }

    @ApiOperation(value = "分销数据核心数据统计")
    @ApiResponse(response = AgentDataStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAgentData")
    public Result<AgentDataStatisticsVo> getAgentData(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                          AgentDataStatisticsDto agentDataStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            agentDataStatisticsDto.setBusinessId(businessInfo.getId());
        }

        agentDataStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAgentData(agentDataStatisticsDto));
    }

    @ApiOperation(value = "分销数据核心数据趋势统计")
    @ApiResponse(response = AgentDataTrendStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getAgentDataTrend")
    public Result<List<AgentDataTrendStatisticsVo>> getAgentDataTrend(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                                                      AgentDataTrendStatisticsDto agentDataTrendStatisticsDto) {
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            agentDataTrendStatisticsDto.setBusinessId(businessInfo.getId());
        }

        agentDataTrendStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(statisticsBiz.getAgentDataTrend(agentDataTrendStatisticsDto));
    }

}
